import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Script } from './script.entity';

@Entity('script_executions')
export class ScriptExecution {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'script_id' })
  scriptId: number;

  @Column({ type: 'enum', enum: ['running', 'completed', 'failed', 'cancelled'], default: 'running' })
  status: 'running' | 'completed' | 'failed' | 'cancelled';

  @Column({ type: 'text', nullable: true })
  output: string;

  @Column({ type: 'text', nullable: true })
  error: string;

  @Column({ name: 'exit_code', nullable: true })
  exitCode: number;

  @Column({ name: 'start_time' })
  startTime: Date;

  @Column({ name: 'end_time', nullable: true })
  endTime: Date;

  @Column({ name: 'executed_by', nullable: true })
  executedBy: number;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @ManyToOne(() => Script)
  @JoinColumn({ name: 'script_id' })
  script: Script;
}